package com.itWaiLong.Result;

import com.itWaiLong.AppException.AppException;
import com.itWaiLong.AppException.GlobalExceptionHandler;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

@Data
@AllArgsConstructor
@NoArgsConstructor
public class Result<T> {
    private int status;//状态码
    private String message;//响应信息
    private T data;//响应数据

    public static <T> Result<T> success(T data) {
        return new Result<>(200,"操作成功",data);
    }

    public static Result success() {
        return new Result<>(200,"操作成功",null);
    }

    public static Result fail(String message) {
        return new Result<>(1,"操作失败",message);
    }

    //响应自定义异常
    public static Result defineFail(GlobalExceptionHandler errorCode) {
        Result result = new Result();
        result.setStatus(errorCode.getCode());//设置响应状态码
        result.setMessage(errorCode.getMessage());//设置响应数据
        result.setData(null);
        return result;
    }

}
